﻿<template id="@(ViewBag.GetCompTemplate("reset"))">
    <el-dialog v-model="visible" :width="400" :title="title" :destroy-on-close="true" :close-on-click-modal="false" :close-on-press-escape="false" draggable v-on:close="closed">
        <el-divider class="layout-page-form-top-border"></el-divider>
        <el-form ref="formRef" :rules="rules" :disabled="disabled" :model="record" :hide-required-asterisk="disabled" label-width="auto" label-suffix=" :">
            <el-form-item label="用户名" prop="Username">
                <el-input :disabled="true" v-model="record.Username"></el-input>
            </el-form-item>
            <el-form-item label="新密码" prop="Password">
                <el-input v-model="record.Password" type="password" show-password></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button v-on:click="close">取消</el-button>
            <el-button type="primary" v-on:click="submit">确定</el-button>
        </template>
    </el-dialog>
</template>
<script type="text/javascript">
    var @(ViewBag.GetCompName("reset")) = {
        template: "#@(ViewBag.GetCompTemplate("reset"))", data() {
            return {
                path: "@(ViewBag.PagePath)",
                pwdFormat: "@(ViewBag.PwdFormat)",
                visible: false,
                title: "用户重置密码",
                rules: {
                    Password: [{
                        validator: (rule, value, callback) => {
                            var format = this.pwdFormat || "简单";
                            if (!value) {
                                return callback(new Error('请填写用户密码'));
                            }
                            if (format == "简单" || format == "复杂") {
                                if (value.length < 8 || value.length > 20) {
                                    return callback(new Error('密码长度必须在8到20位之间'));
                                }
                            }
                            if (format == "复杂") {
                                if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_!@@#$%^&*`~()-+=]).+$/.test(value)) {
                                    return callback(new Error('密码必须包含大小写字母、数字、特殊字符'));
                                }
                            }
                            callback();
                        }, required: true
                    }]
                },
                record: {},
                disabled: false
            }
        },
        methods: {
            open(record){
                var that = this;
                that.record = record;
                that.visible = true;
            },
            close(){
                this.visible = false;
            },
            closed(){
                this.record = {};
            },
            submit(){
                var that = this;
                that.$refs.formRef.validate(valid => {
                    if (valid) {
                        app.func.submit(`${that.path}/reset`, that.record, that.close);
                    }
                });
            }
        },
        mounted() { }
    };
</script>